/*
 * @Author: [you name]
 * @Date: 2021-11-23 14:21:59
 * @LastEditors: [you name]
 * @LastEditTime: 2021-11-24 10:53:02
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \aaa\src\permission\getUserRouter.ts
 */
import {systemRouterList} from '@/router/modules/system'
import {commodityRouterList} from '@/router/modules/commodity'
import {courseRouterList} from '@/router/modules/course'

export const routerLists = [commodityRouterList, systemRouterList,courseRouterList];

export const getUserRouteObj = (store)=> {
  const sourceRouter = routerLists;
  // 后期通过对比当前角色权限进行筛选渲染，目前这里先不做处理，返回所有的
  store.dispatch('SET_ROUTER_TREE',sourceRouter);
  return sourceRouter;
}

//获取所属权限树摇后的用户路由树

// 将路由树转换成权限页面的权限树，默认所有的
const copyTree = (obj: any) => {
  if (obj.meta.isShow) {
    const children = []
    if (obj.children && obj.children.length > 0) {
      obj.children.forEach(item => {
        if (item.meta.isShow && item.meta.isShow === true) {
          children.push(copyTree(item))
        }
      });
    }

    let roles = []
    if (obj.meta.roles && obj.meta.roles.length > 0) {
      obj.meta.roles.forEach(role => {
        roles.push({
          authorityCode: role.authorityCode,
          pauthorityCode: role.pauthorityCode,
          label: role.label,
          isChecked: false
        })
      });
    }

    const result = {
      label: obj.meta.title,
      authorityCode: obj.path || null,
      roles: roles.length > 0 ? roles : null,
      children: children.length > 0 ? children : null,
      isChecked: false,
      indeterminate: false,
      isShow: true
    }
    return result
  }
}